package com.lsa.letcode.the23.mergeKsortedLists;

import org.junit.Test;

import com.lsa.letcode.common.LetCodeTestBase;
import com.lsa.letcode.common.ListNode;

public class MergeKsortedListsTest extends LetCodeTestBase {
	@Test
	public void test() throws Exception {
		test(asList(2, 3, 4, 4, 5), asList(2), asList(3), asList(4, 5),
				asList(4));
//
		test(asList(1, 2, 3, 10, 11, 12, 20, 21, 22, 30, 31, 32, 41, 100, 101,
				102, 103, 200, 300),
				asList(1, 2, 3, 10, 20, 30, 100, 200, 300),
				asList(11, 12, 21, 22, 31, 32, 41), asList(101, 102, 103));

		test(asList(1, 2, 3, 4, 5, 5, 6), asList(1, 3, 5), asList(2, 4, 5, 6));
		test(asList(1, 2, 3, 4, 5, 5, 6, 7, 8, 9, 10, 10, 11, 12, 13, 14, 15,
				15, 15, 17, 27), asList(1, 3, 5, 7, 9, 11, 13),
				asList(2, 4, 5, 6, 8, 10, 12, 14), asList(10, 17, 27),
				asList(15, 15, 15));
	}

	private void test(ListNode expected, ListNode... nodes) throws Exception {
		Solution s = new Solution();
		assertEqual(expected, s.mergeKLists(nodes));
	}
}
